package com.spzx.payment.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;


/**
 * Package: com.spzx.payment.config
 *
 * @author xiongkunYang
 * @description:
 * @since 2025/6/9 14:02
 */
@SpringBootConfiguration
public class AlipayConfig {

    @Value("${alipay.server_url}")
    private String serverUrl;
    @Value("${alipay.app_id}")
    private String appId;
    @Value("${alipay.private_key}")
    private String privateKey;


    public final static String FORMAT = "json";
    public final static String CHARSET = "utf-8";
    public final static String SIGN_TYPE = "RSA2";

    public static String alipayPublicKey;
    public static String returnUrl;
    public static String notifyUrl;
    public static String returnOrderUrl;

    @Value("${alipay.alipay_public_key}")
    public void setAlipayPublicKey(String alipayPublicKey) {
        AlipayConfig.alipayPublicKey = alipayPublicKey;
    }

    @Value("${alipay.return_url}")
    public void setReturnUrl(String returnUrl) {
        AlipayConfig.returnUrl = returnUrl;
    }

    @Value("${alipay.notify_url}")
    public void setNotifyUrl(String notifyUrl) {
        AlipayConfig.notifyUrl = notifyUrl;
    }

    @Value("${alipay.return_order_url}")
    public void setReturnOrderUrl(String returnOrderUrl) {
        AlipayConfig.returnOrderUrl = returnOrderUrl;
    }

    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(serverUrl, appId, privateKey, FORMAT, CHARSET, alipayPublicKey, SIGN_TYPE);
    }
}